/*
 * PopupCanvassResult.hpp
 *
 *  Created on: Jul 17, 2012
 *      Author: guillou
 */

#ifndef POPUPCANVASSRESULT_HPP_
#define POPUPCANVASSRESULT_HPP_

#include <PopupUsersManager.hpp>
#include <ui_canvassresultwidget.h>

class PopupCanvassResult : public QWidget, private Ui_CanvassResultWidget
{
  Q_OBJECT

public:
  virtual ~PopupCanvassResult() {}
  PopupCanvassResult(QWidget *p_parent = 0,
                     const std::string & p_choiceLabel = "",
                     int p_nbVoters = 0,
                     bool p_isAnonymous = true)
  : QWidget(p_parent), m_anonymous(p_isAnonymous)
  {
    setupUi(this);
    label->setText(p_choiceLabel.c_str());
    m_electors->setVisible(!p_isAnonymous);
    progressBar->setValue(0);
    progressBar->setMaximum(p_nbVoters);
  }

  void addVote(Popup::UserID p_voterID) {
    progressBar->setValue(progressBar->value() + 1);
    if (!m_anonymous && p_voterID != 0) {
      QString _voters = m_electors->text();
      if (_voters.length() > 0) {
        _voters += ", ";
      }
      _voters += QString(Popup::getNickname(p_voterID).c_str());
      m_electors->setText(_voters);
    }
  }
private:
  bool m_anonymous;
};

#endif /* POPUPCANVASSRESULT_HPP_ */
